package test3;

import java.util.Random;

public class test {
    public static void main(String[] args) {
        //需求
        //把一个二维数组中的数据:0~15打乱顺序
        //然后再按照4个一组的方式添加到二维数组当中
        int[] tempArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
        Random r = new Random();
        for (int i = 0; i < tempArray.length; i++) {
            int index = r.nextInt(tempArray.length);
            int temp = tempArray[i];
            tempArray[i] = tempArray[index];
            tempArray[index] = temp;

        }
        //打印看看
        for (int i = 0; i < tempArray.length; i++) {
            System.out.print(tempArray[i] + " ");
        }
        System.out.println();
        //一维数组的数据打乱好了,现在创建二维数组
        int [][]date=new int[4][4];
        ///遍历一维数组tempArr得到每一个元素,把每个元素一次添加在二维数组当中
        for (int i = 0; i < tempArray.length; i++) {
            date[i/4][i%4]=tempArray[i];
        }
        for (int i = 0; i < date.length; i++) {
            for (int j = 0; j < date[i].length; j++) {
                System.out.print(date[i][j] + " ");
            }
            System.out.println();
        }

    }
}
